<?php
namespace backend\controllers;

use backend\models\course\CourseOrder;
use Yii;
use backend\controllers\BaseController;
use backend\models\user\User;
use backend\models\user\UserLog;
use backend\models\course\Course;
use backend\models\course\CoursePeriod;
use backend\models\site\UserCourser;

/**
 * 后台首页模块
 * @author 王明东
 */
class SiteController extends BaseController
{
    /**
     * @inheritdoc  登陆成功后首页
     */
    public function actionIndex()
    {
		
		
	    $today_start        = strtotime(date('Y-m-d 00:00:00'));//今日开始
	    $today_end          = strtotime(date('Y-m-d 23:59:59'));//今日结束
	    $yesterday_start    = strtotime(date("Y-m-d 00:00:00",strtotime("-1 day")));//昨日开始
	    $yesterday_end      = strtotime(date("Y-m-d 23:59:59",strtotime("-1 day")));//昨日结束
	    /* 今日新注册用户数 */
		$today_user = User::TodayUser($today_start,$today_end);
        
	    /* 昨日注册用户数 */
	    $yesterday_user = User::YesterdayUser($yesterday_start,$yesterday_end);
        
	    /* 用户登录数（不含重复登录）今日 */
		$today_login = UserLog::TodayLogin($today_start,$today_end);
        
	    /* 用户登录数（不含重复登录）昨日 */
	    $yesterday_login = UserLog::YesterdayLogin($yesterday_start,$yesterday_end);
 
	    /* 新增课程数  今日 */
		$today_course = Course::TodayCourse($today_start,$today_end);

	    /* 新增课程数  昨日 */
	    $yesterday_course = Course::YesterdayCourse($yesterday_start,$yesterday_end);
     
	    /* 新增课时数  今日 */
	    $today_section = CoursePeriod::TodaySection($today_start,$today_end);

	    /* 新增课时数  昨日 */
	    $yesterday_section = CoursePeriod::YesterdaySection($yesterday_start,$yesterday_end);

	    /* 加入学习数  今日 */
	    $today_study_num = Course::TodayStudynum($today_start,$today_end);

	    /* 加入学习数  昨日 */
	    $yesterday_study_num = Course::YesterdayStudynum($yesterday_start,$yesterday_end);

	    /* 购买课程数  今日 */
	    $today_buycourser = UserCourser::TodayBuycourser($today_start,$today_end);

	    /* 购买课程数  昨日 */
	    $yesterday_buycourser = UserCourser::YesterdayBuycourser($yesterday_start,$yesterday_end);

	    /* 完成课时学习数  今日 */
	    $today_coursecomplete = UserCourser::TodayCoursecomplete($today_start,$today_end);

	    /* 完成课时学习数  昨日 */
	    $yesterday_coursecomplete = UserCourser::YesterdayCoursecomplete($yesterday_start,$yesterday_end);

	    /* 视频观看数（含重复打开） 今日 */
	    $today_seevideo = UserLog::TodaySeevideo($today_start,$today_end);

	    /* 视频观看数（含重复打开） 昨日 */
	    $yesterday_seevideo = UserLog::YesterdaySeevideo($yesterday_start,$yesterday_end);
	    /* 营收额  今日 */
	    $today_revenue = CourseOrder::TodayRevenue($today_start,$today_end);

	    /* 营收额  昨日 */
	    $yesterday_revenue = CourseOrder::YesterdayRevenue($yesterday_start,$yesterday_end);

	    /*课程总数  今日*/
	    $today_allcourse = Course::TodayAllcourse();
       
	    /*课程总数  昨日*/
	    $yesterday_allcourse = Course::YseterdayAllcourse($yesterday_end);

	    /*用户总数  今日*/
	    $today_alluser = User::TodayAlluser();
          
	    /*用户总数  昨日*/
	    $yesterday_alluser = User::YseterdayAlluser($yesterday_end);
        
        // $this->renderPartial('index',
        return $this->render('index',
	        [
		        'today_user'                => $today_user,//今日新注册用户数
		        'yesterday_user'            => $yesterday_user,//昨日注册用户数
		        'today_login'               => $today_login,//用户登录数（不含重复登录）今日
		        'yesterday_login'           => $yesterday_login,//用户登录数（不含重复登录）昨日
		        'today_course'              => $today_course,//新增课程数  今日
		        'yesterday_course'          => $yesterday_course,//新增课程数  昨日
		        'today_section'             => $today_section,//新增课时数  今日
		        'yesterday_section'         => $yesterday_section,//新增课时数  昨日
		        'today_study_num'           => $today_study_num,//加入学习数  今日
		        'yesterday_study_num'       => $yesterday_study_num,//加入学习数  昨日
		        'today_buycourser'          => $today_buycourser,//购买课程数  今日
		        'yesterday_buycourser'      => $yesterday_buycourser,//购买课程数  今日
		        'today_coursecomplete'      => $today_coursecomplete,//完成课时学习数  今日
		        'yesterday_coursecomplete'  => $yesterday_coursecomplete,//完成课时学习数  昨日
		        'today_seevideo'            => $today_seevideo,//视频观看数（含重复打开） 今日
		        'yesterday_seevideo'        => $yesterday_seevideo,//视频观看数（含重复打开） 昨日
		        'today_revenue'             => $today_revenue,//营收额  今日
		        'yesterday_revenue'         => $yesterday_revenue,//营收额  昨日
		        'today_allcourse'           => $today_allcourse,//课程总数  今日
		        'yesterday_allcourse'       => $yesterday_allcourse,//课程总数  昨日
		        'today_alluser'             => $today_alluser,//用户总数  今日
		        'yesterday_alluser'         => $yesterday_alluser,//用户总数  昨日
            ]
        );
    }
    
    
}
